package com.ubao.util;


import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;

import com.ubao.activity.MyApp;


public class ScreenReceiver extends BroadcastReceiver {
	// thanks Jason
	public static boolean bScreenOf_NetOn = false;

	@Override
	public void onReceive(Context arg0, Intent arg1) {
		if (arg1.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
			bScreenOf_NetOn = MyApp.hasInitNetWork ? true : false;
			ConnectivityManager connectivityManager = (ConnectivityManager) arg0
					.getSystemService(Context.CONNECTIVITY_SERVICE);
			NetworkInfo activeNetInfo = connectivityManager
					.getActiveNetworkInfo();
			if (activeNetInfo != null && activeNetInfo.getTypeName() != null) {
				if (activeNetInfo.getTypeName().equals("WIFI")) {
					Log.v("out", "WIFI");
				}
				if (activeNetInfo.getTypeName().equals("mobile")) {
					Log.v("out", "mobile");
				}
			}
		} else if (arg1.getAction().equals(Intent.ACTION_SCREEN_ON)) {
			// and do whatever you need to do here
			bScreenOf_NetOn = MyApp.hasInitNetWork ? true : false;
		}
	}
}
